{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9c439761",
   "metadata": {},
   "source": [
    "## 显示单词“Milliways”中的所有元音，包括所有重复"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4ec8d711",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c0d423a9",
   "metadata": {},
   "source": [
    "## 增加一些代码，使用一个列表来避免重复。会显示单词“Milliways”中找到的唯一元音组成的列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "56bbbef1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "98b905fe",
   "metadata": {},
   "source": [
    "## 这一元音程序的第三个版本“vowels3.py”，会显示从用户输入的第一个单词中找到唯一元音"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "738a05df",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels:a\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = input(\"Provide a word to search for vowels:\")\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "91de6e69",
   "metadata": {},
   "source": [
    "## python与“for”循环的合作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "1af0a2ca",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t M\n",
      "\t a\n",
      "\t r\n",
      "\t v\n",
      "\t i\n",
      "\t n\n"
     ]
    }
   ],
   "source": [
    "paranoid_android = \"Marvin\"\n",
    "letters = list(paranoid_android)\n",
    "for char in letters:\n",
    "    print('\\t',char)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57a88931",
   "metadata": {},
   "source": [
    "## python的括号记法，用3个切片来抽取和显示一个字母列表的片段"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "ef8f3830",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t M\n",
      "\t a\n",
      "\t r\n",
      "\t v\n",
      "\t i\n",
      "\t n\n",
      "\n",
      "\t\t M\n",
      "\t\t a\n",
      "\t\t r\n",
      "\t\t v\n",
      "\t\t i\n",
      "\t\t n\n",
      "\t\t ,\n",
      "\n",
      "\t\t\t a\n",
      "\t\t\t r\n",
      "\t\t\t a\n",
      "\t\t\t n\n",
      "\t\t\t o\n",
      "\t\t\t i\n",
      "\t\t\t d\n",
      "\t\t\t  \n"
     ]
    }
   ],
   "source": [
    "paranoid_android = \"Marvin,the Paranoid Android\"\n",
    "letters = list(paranoid_android)\n",
    "for char in letters[:6]:\n",
    "    print('\\t',char)\n",
    "print()\n",
    "for char in letters[:7]:\n",
    "    print('\\t'*2,char)\n",
    "print()\n",
    "for char in letters[12:20]:\n",
    "    print('\\t'*3,char)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "859f27d9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
